<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><#if isAddAction>添加<#else>编辑</#if>出库登记信息</title>
<#include "/admin/common_css.ftl">
<#include "/admin/common_js.ftl">
<script type="text/javascript" src="${base}/apache/common/js/jquery.tools.js"></script>
<script type="text/javascript" src="${base}/apache/common/js/jquery.validate.js"></script>
<script type="text/javascript" src="${base}/apache/common/js/jquery.validate.methods.js"></script>
<script type="text/javascript" src="${base}/apache/common/editor/kindeditor.js"></script>
<script charset="utf-8" src="${base}/apache/common/editor/lang/zh_CN.js"></script>
<script type="text/javascript" src="${base}/apache/date97/WdatePicker.js"></script>


<script type="text/javascript">
$(function() {
	var $validateErrorContainer = $("#validateErrorContainer");
	var $validateErrorLabelContainer = $("#validateErrorContainer ul");
	var $validateForm = $("#validateForm");

  // Tab效果
  $("ul.tab").tabs(".tabContent");
  
  	var $goodsAttributeTable = $("#goodsAttributeTable");
	var $addGoodsAttributeButton = $("#addGoodsAttributeButton");
  
  // 增加商品属性
	var goodsAttributeIndex = ${(stock.stockDetailSet?size)!0};
	$addGoodsAttributeButton.click( function() {
	   <@compress single_line = true>
			var goodsAttributeTrHtml = 
			'<tr class="goodsAttributeTr">
				<td>
						<input type="hidden" />
					</td>
				<td>
						<input type="text" name="productAttributeList[' + goodsAttributeIndex + '].consumable.sn" class="formText goodsAttributeListName" value="${(stockItem.consumable.sn)!}" />
					</td>
					<td>
						<input type="text" name="productAttributeList[' + goodsAttributeIndex + '].count" class="formText goodsAttributeListOrderList" value="${(stockItem.count)!}" />
					</td>
					<td>
						<input type="text" name="productAttributeList[' + goodsAttributeIndex + '].labname" class="formText" value="${(stockItem.labname)!}" />
					</td>
					
					<td>
						<input type="text" name="productAttributeList[' + goodsAttributeIndex + '].deployment" class="formText" value="${(stockItem.deployment)!}" />
					</td>
				<td>
					<span class="deleteIcon deleteGoodsAttributeIcon" title="删 除">&nbsp;</span>
				</td>
			</tr>';
		</@compress>
		
		if ($goodsAttributeTable.find(".goodsAttributeTr").length >= 20) {
			$.dialog({type: "warn", content: "商品属性个数超出限制!", modal: true, autoCloseTime: 3000});
		} else {
			$goodsAttributeTable.append(goodsAttributeTrHtml);
			goodsAttributeIndex ++;
		}
	});
	
	// 修改商品属性类型
	$("#goodsAttributeTable .attributeType").live("click", function() {
		var $this = $(this);
		var $optionText = $this.parent().parent().find(".optionText")
		if ($this.val() == "filter") {
			$optionText.attr("disabled", false).show();
		} else {
			$optionText.attr("disabled", true).hide();
		}
	});
	
	// 删除商品属性
	$("#goodsAttributeTable .deleteGoodsAttributeIcon").live("click", function() {
		$(this).parent().parent().remove();
	});	
	
	// 表单验证
	$validateForm.validate({
		errorContainer: $validateErrorContainer,
		errorLabelContainer: $validateErrorLabelContainer,
		wrapper: "li",
		errorClass: "validateError",
		ignoreTitle: true,
		rules: {
			"sdate": "required",
			"code": "required"
		},
		messages: {
			"sdate": "请填写入库日期",
			"code": "请填写入库编号"
		},
		submitHandler: function(form) {
			$(form).find(":submit").attr("disabled", true);
			form.submit();
		}
	});	
	
	$.validator.addMethod("goodsAttributeListNameRequired", $.validator.methods.required, "请填写入库项物品编号");
	$.validator.addMethod("goodsAttributeListOrderListRequired", $.validator.methods.required, "请填写入库物品数量");
	$.validator.addMethod("goodsAttributeListOrderListDigits", $.validator.methods.digits, "物品数量必须为零或正整数");
	
	$.validator.addClassRules("goodsAttributeListName", {
		goodsAttributeListNameRequired: true
	});
	$.validator.addClassRules("goodsAttributeListOrderList", {
		goodsAttributeListOrderListRequired : true,
		goodsAttributeListOrderListDigits: true
	});
	
});

</script>
</head>
<body class="input">
	<div class="bar">
		<#if isAddAction>添加出库登记信息<#else>编辑出库登记信息</#if>
	</div>
	<div id="validateErrorContainer" class="validateErrorContainer">
		<div class="validateErrorTitle">以下信息填写有误,请重新填写</div>
		<ul></ul>
	</div>
	<div class="body">
		<form id="validateForm" enctype="multipart/form-data" action="<#if isAddAction>../save/0<#else>../../update/0</#if>" method="post">
			<input type="hidden" name="id" value="${(stock.id)!}" />
			
			<ul id="tab" class="tab">
				<li>
					<input type="button" value="基本信息" hidefocus />
				</li>
				<li>
					<input type="button" value="出库项" hidefocus />
				</li>
			</ul>
			<table class="inputTable tabContent">
				<tr>
					<th>
						出库日期: 
					</th>
					<td>
						<input type="text" name="sdate" class="formText" value="${(stock.date)!}"  onclick="WdatePicker()" />
						<label class="requireField">*</label>
					</td>
				</tr>
				<tr>
					<th>
						出库编号: 
					</th>
					<td>
						<input type="text" name="code" class="formText" value="${(stock.code)!}" />
						<label class="requireField">*</label>
					</td>
				</tr>
				<tr>
					<th>
						经手人: 
					</th>
					<td>
						<input type="text" name="stockor" class="formText" value="${(stock.stockor)!}"/>
						<label class="requireField">*</label>
					</td>
				</tr>
				<tr>
					<th>
						摘要: 
					</th>
					<td>
						<input type="text" name="description" class="formText" value="${(stock.description)!}" />
						<label class="requireField">*</label>
					</td>
				</tr>
				<tr>
					<th>
						备注: 
					</th>
					<td>
						<input type="text" name="comments" class="formText" value="${(stock.comments)!}" />
						<label class="requireField">*</label>
					</td>
				</tr>
			</table>
			<table id="goodsAttributeTable" class="inputTable tabContent">
				<tr class="noneHover">
					<td colspan="5">
						<input type="button" id="addGoodsAttributeButton" class="formButton" value="增加物品" hidefocus />
					</td>
				</tr>
				<tr class="title">
					<th>
					</th>
					<th>
						物品编号: 
					</th>
					<th>
						数量: 
					</th>
					<th>
						实验室名称: 
					</th>
					<th>
						部门名称: 
					</th>
					</tr>
					<#list (stock.stockDetailSet)! as stockItem>
				<tr class="goodsAttributeTr">
					<td>
						<input type="hidden" name="productAttributeList[${stockItem_index}].id" value="${(stockItem.id)!}" />
					</td>
					<td>
						<input type="text" name="consumable.sn" class="formText goodsAttributeListName" value="${(stockItem.consumable.sn)!}" />
					</td>
					<td>
						<input type="text" name="count" class="formText goodsAttributeListOrderList" value="${(stockItem.count)!}" />
					</td>
					<td>
						<input type="text" name="labname" class="formText" value="${(stockItem.labname)!}" />
					</td>
					
					<td>
						<input type="text" name="deployment" class="formText" value="${(stockItem.deployment)!}" />
					</td>
				</tr>
				</#list>
			</table>
			<div class="buttonArea">
				<input type="submit" class="formButton" value="确  定" hidefocus />&nbsp;&nbsp;
				<input type="button" class="formButton" onclick="window.history.back(); return false;" value="返  回" hidefocus />
			</div>
		</form>
	</div>
</body>
</html>